/*
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

Anser:232792560
Time:12.614µs
*/
package main

import (
	"fmt"
	"time"
)

func main() {
	tstart := time.Now()
	n := 1
	for i := 1; i <= 20; i++ {
		n = LowestCommonMultiple(n, i)
	}
	fmt.Println(n)
	tend := time.Now()
	fmt.Println(tend.Sub(tstart))
}

// GreatestCommonDivisor 最大公约数
func GreatestCommonDivisor(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

// LowestCommonMultiple 最小公倍数
func LowestCommonMultiple(a, b int) int {
	return a * b / GreatestCommonDivisor(a, b)
}
